-
Notifications
You must be signed in to change notification settings - Fork 648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wyatt Wicks #433
base: master
Are you sure you want to change the base?
Wyatt Wicks #433
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wyatt, good work!
p "1 speckled frog sat on a log" | ||
\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of an anti-patttern since puts
automatically adds a new line at the end of a string.
number_frogs = (1..10).to_a | ||
number_frogs.sort! {|x, y| y <=> x} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work using range and array to set up your number_frogs
p "eating some most delicious bugs." | ||
\ | ||
p "One jumped in the pool where its nice and cool," | ||
\ | ||
|
||
if new_number == 0 | ||
p "then there were no more speckled frogs!" | ||
elsif new_number == 1 | ||
p "then there was one speckled frog." | ||
else | ||
p "then there were #{new_number} speckled frogs." | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work using iteration and looking for where you can DRY (don't repeat yourself) your code.
message.chars.map {|char| alphabet.include?(char.downcase) ? | ||
alphabet[alphabet.find_index(char.downcase) + shift - alphabet.size] : char}.join |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a LOT going on here. As a rule of thumb, if you have more than one line in an enumerable block, use do
and end
instead of {}
for readability.
Warning: Be very careful about copying and pasting solutions and changing variable names. Understanding how those methods all work together will allow you to design your solutions with intention.
3. Now comes the actual code. We use message.chars to separate whatever message we type in to a new array of individual characters. then we use the .map command to map out this array of characters in a new way. | ||
4. the code after the .map command is telling the computer that for each character in our array, we first check if the character is in the alphabet array that we created earlier. This eliminates spaces, symbols, and numbers so the end result only has the characters shifted and not the other spaces and punction marks. using the .downcase command will make it so that even if the letters in the message are capitalized, they will still be able to be found in our alphabet array as those letters are all lower case. | ||
5. then we use alphabet.find_index(char.downcase) to find the numbered position of each character in the alphabet array. | ||
6. we then add shift to the index number to each character. shift has been defined as the number you want the letters to move, so by adding that number to each character, the new character is the value of the old character's index plus the amount to shift. | ||
7. I then subtracted the size of the alphabet (26) to account for any character that has been shifted higher than the amount of characters in the alphabet. This also wraps the characters around the alphabet again because there is no value in alphabet for anything higher than 26. | ||
8. I then close out my maps bracket with :char so the program knows to do the above for every character in the message. I then use the .join command to take those new characters and rejoin them in to words again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work defining the methods for yourself before implementing a solution from your research (stack overflow). I think you've explained all of these except the ternary operator ? :
map
include?
downcase
? :
find_index
size
join
A different challenge that is more common in programming, would be to write out the steps of what you want to do in plain language first and then find the pieces of code to fit those steps.
def add_topping(topping) | ||
@toppings.append(topping) | ||
puts "You added #{topping} to your burrito!" | ||
end | ||
|
||
def remove_topping(topping) | ||
@toppings.delete(topping) | ||
puts "You removed #{topping} from your burrito!" | ||
end | ||
|
||
def change_protein(protein) | ||
@protein = protein | ||
puts "You changed your protein to #{protein}!" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job updating the attributes of the class.
Here is my prework!